package com.example.xjt.restful;


import lombok.Getter;

/**
 * 中文-返回码-枚举
 */
@Getter
public enum ResultCodeEnum {
    SUCCESS(0, "操作成功"),
    CLIENT_IS_NOT_EXIST(1101, "客户端不存在"),
    TOKEN_IS_INVALID(1102, "token无效"),
    VERITY_GEN_ERROR(9801, "验证码生成失败"),
    VERITY_IDENTITY_ERROR(9803, "验证码验证失败"),
    TOKEN_NULL(9777, "请求头里没有token"),
    TOKEN_TIME_OUT(9776, "token已过期,请重新登录"),
    TOKEN_USER_ALREADY_SIGN(9775, "token用户已登录,请退出重登后再请求本接口"),
    LOGOUT_FAILED(2201, "退出失败"),
    FAILED(9500, "响应失败"),
    BUSY(9600, "系统繁忙"),
    ACCOUNT_PASS_FAILED(9301, "密码错误"),
    ACCOUNT_NOT_EXIST(9302, "用户名不存在"),
    ACCOUNT_DISABLED(9303, "用户没有权限/已禁用"),
    NOT_LOGIN(9403, "未登录"),
    REQ_BODY_IS_NULL(9995, "缺失请求体requestBody"),
    VALIDATE_FAILED(9996, "参数校验异常"),
    ARITHMETIC_FAILED(9997, "算术异常"),
    ARRAY_INDEX_OUT_OF_BOUNDS_FAILED(9998, "数组越界异常"),
    USER_IS_USING(7701, "目标用户正在使用中"),

    ERROR(9999, "未知错误"),

    BAD_REQUEST(400, "错误的请求"),
    UNAUTHORIZED(401,"未认证"),
    FORBIDDEN(403,"被拒绝"),
    NOT_FOUND(404,"找不到资源"),
    UNSUPPORTED_MEDIA_TYPE(415,"不支持的媒体类型"),


    BIZ_ERROR(5001, "业务错误"),
    BIZ_ERROR_1(500101, "业务错误1"),
    BIZ_ERROR_2(500102, "业务错误2");

    private int code;
    private String msg;


    ResultCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 根据code，返回对应message
     *
     * @param code resultCode码
     * @return String 对应message
     */
    public static String getZhMsgByCode(int code) {
        for (ResultCodeEnum engEnum : ResultCodeEnum.values()) {
            if (engEnum.getCode() == code) {
                return engEnum.getMsg();
            }
        }
        return ResultCodeEnum.ERROR.getMsg();
    }



}